package com.mission.schedule.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.lcf.refreshlibrary.PullToRefreshBase;
import com.lcf.refreshlibrary.PullToRefreshListView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.mission.schedule.R;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.NoteLYBean;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.constants.URLConstants;
import com.mission.schedule.my160920.widget.CircleImageView;
import com.mission.schedule.utils.ProgressUtil;
import com.mission.schedule.utils.SharedPrefUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;


@SuppressLint({"SimpleDateFormat", "HandlerLeak"})
public class QDZoneDetailActivity extends BaseActivity implements OnClickListener {


    private LinearLayout back,myfriend_ll,myfriend_ll_i;
    private RelativeLayout my_friend_ll_right;
    PullToRefreshListView listview;
    Context context;
    CircleImageView head_img;
    TextView head_name;

    SharedPrefUtil sharedPrefUtil = null;

    String title = "", title1 = "";
    String titleId;
    String path;
    String time;
    String name;
    String rednum;
    String goodnum = "0";
    String num;
    String userid;
    String uid;
    int type = 1;

    boolean isGood = false;
    boolean isOnRefresh = false;

    ListAdapter listAdapter;
    int stylee = 0;
    int isRead = 0;
    String imageUrl = "";
    int id = 0;

    @Override
    protected void setListener() {
        back.setOnClickListener(this);
        my_friend_ll_right.setOnClickListener(this);

        listview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {


            @Override
            public void onPullDownToRefresh(
                    PullToRefreshBase<ListView> refreshView) {
                isOnRefresh = true;
                getdata();
            }

            @Override
            public void onPullUpToRefresh(
                    PullToRefreshBase<ListView> refreshView) {
                listview.onRefreshComplete();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (listAdapter != null) {
            listAdapter.notifyDataSetChanged();
        }
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.dx_detail_activity);
        title = getIntent().getStringExtra("title");
        titleId = getIntent().getStringExtra("titleId");
        path = getIntent().getStringExtra("path");
        time = getIntent().getStringExtra("time");
        name = getIntent().getStringExtra("name");
        rednum = getIntent().getStringExtra("redNum");
        goodnum = getIntent().getStringExtra("goodNum");
        num = getIntent().getStringExtra("num");
        uid = getIntent().getStringExtra("uid");
        type = getIntent().getIntExtra("type", 1);
        stylee = getIntent().getIntExtra("stylee", 0);
        rednum = (Integer.valueOf(rednum) + 1) + "";
        isRead = getIntent().getIntExtra("isRead", 0);
        imageUrl = getIntent().getStringExtra("imageUrl");
        id = getIntent().getIntExtra("id",0);

        back = findViewById(R.id.top_ll_back);
        my_friend_ll_right = findViewById(R.id.my_friend_ll_right);
        my_friend_ll_right.setVisibility(View.GONE);
        listview = findViewById(R.id.listview);
        listview.setMode(PullToRefreshBase.Mode.DISABLED);
        myfriend_ll = findViewById(R.id.myfriend_ll);
        myfriend_ll_i = findViewById(R.id.myfriend_ll_i);
        head_name = findViewById(R.id.head_name);
        head_img = findViewById(R.id.head_img);
        myfriend_ll_i.setVisibility(View.VISIBLE);
        myfriend_ll.setVisibility(View.VISIBLE);
    }
    ImageLoader imageLoader;
    ImageLoadingListener animateFirstListener = new AnimateFirstDisplayListener();

    @Override
    protected void init(Bundle savedInstanceState) {
        context = this;

        sharedPrefUtil = new SharedPrefUtil(context, ShareFile.USERFILE);
        imageLoader = ImageLoader.getInstance();
        userid = sharedPrefUtil.getString(this, ShareFile.USERFILE, ShareFile.USERID, "");
//        queryISGood();
        getdata();

        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showStubImage(R.mipmap.b1)
                .showImageForEmptyUri(R.mipmap.b1)
                .showImageOnFail(R.mipmap.b1).cacheInMemory(true)
                .cacheOnDisc(true).cacheInMemory(true)
                .bitmapConfig(Bitmap.Config.RGB_565) // 设置图片的解码类型
                .build();

        imageLoader.displayImage(imageUrl, head_img, options, animateFirstListener);
        head_name.setText(name);
    }

    private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {

        static final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());

        @Override
        public void onLoadingComplete(String imageUri, View view,
                                      Bitmap loadedImage) {
            if (loadedImage != null) {
                ImageView imageView = (ImageView) view;
                // 是否第一次显示
                boolean firstDisplay = !displayedImages.contains(imageUri);
                if (firstDisplay) {
                    // 图片淡入效果
                    FadeInBitmapDisplayer.animate(imageView, 500);
                    displayedImages.add(imageUri);
                }
            }
        }
    }
    @Override
    protected void setAdapter() {
        Collections.sort(listBeanList, new Comparator<QDBean.ListBean>() {
            @Override
            public int compare(QDBean.ListBean lhs,
                               QDBean.ListBean rhs) {
                if (lhs.orderId > rhs.orderId) {
                    return 1;
                } else {
                    return -1;
                }
            }
        });
        listAdapter = new ListAdapter(listBeanList);
        listview.setAdapter(listAdapter);
        listAdapter.notifyDataSetChanged();
    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    if (!title1.isEmpty() || title.isEmpty()) {
                        notifyDataSetChanged();
                    }
                    break;
            }
        }
    };

    private void sendh(int what) {
        Message message = new Message();
        message.what = what;
        handler.sendMessage(message);
    }

    ProgressUtil progressUtil = new ProgressUtil();

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.top_ll_back:
                onBackPressed();
                break;

            default:
                break;
        }
    }

//    private void queryISGood() {
//        HttpUtils httpUtils = new HttpUtils(10000);
//        RequestParams params = new RequestParams();
//        params.addBodyParameter("num", num);
//        params.addBodyParameter("uId", userid);
//        httpUtils.send(HttpMethod.POST, URLConstants.清单发现详情是否已赞, params, new RequestCallBack<String>() {
//            @Override
//            public void onSuccess(ResponseInfo<String> responseInfo) {
//                if (!TextUtils.isEmpty(responseInfo.result)) {
//                    Gson gson = new Gson();
//                    QDFXGLListActivity.updateQDFXBean bean = gson.fromJson(responseInfo.result, QDFXGLListActivity.updateQDFXBean.class);
//                    if (bean.status == 0) {
//                        isGood = true;
//                        notifyDataSetChanged();
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(HttpException e, String s) {
//            }
//        });
//    }
//
//    private void good() {
//        HttpUtils httpUtils = new HttpUtils(10000);
//        RequestParams params = new RequestParams();
//        String path;
//        if (type != 1 && type != 5) {
//            path = URLConstants.清单公告点赞;
//            params.addBodyParameter("titleId", titleId);
//            params.addBodyParameter("type", "0");
//        } else {
//            path = URLConstants.清单发现详情点赞;
//            params.addBodyParameter("num", num);
//            params.addBodyParameter("puId", uid);
//        }
//
//        params.addBodyParameter("uId", userid);
//
//        httpUtils.send(HttpMethod.POST, path, params, new RequestCallBack<String>() {
//            @Override
//            public void onSuccess(ResponseInfo<String> responseInfo) {
//                if (!TextUtils.isEmpty(responseInfo.result)) {
//                    Gson gson = new Gson();
//                    QDFXGLListActivity.updateQDFXBean bean = gson.fromJson(responseInfo.result, QDFXGLListActivity.updateQDFXBean.class);
//                    if (bean.status == 0) {
//                        goodnum = (Integer.valueOf(goodnum) + 1) + "";
//                        isGood = true;
//                        isZan = true;
//                        if (type != 1 && type != 5) {
//                            String rizhi = sharedPrefUtil.getString(context,
//                                    ShareFile.USERFILE, ShareFile.CHANGJIANDIANZAN, "");
//                            sharedPrefUtil.putString(context,
//                                    ShareFile.USERFILE, ShareFile.CHANGJIANDIANZAN, rizhi + "," + titleId);
//                        }
//                        notifyDataSetChanged();
//                    }
//
//                    if (bean.status == 4) {
//                        Toast.makeText(QDZoneDetailActivity.this, "已点过赞", Toast.LENGTH_SHORT).show();
//                        isGood = true;
//                        notifyDataSetChanged();
//                    }
//                } else {
//                    Toast.makeText(QDZoneDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
//                }
//            }
//
//            @Override
//            public void onFailure(HttpException e, String s) {
//                Toast.makeText(QDZoneDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
//            }
//        });
//    }

    List<QDBean.ListBean> listBeanList = new ArrayList<>();

    private void getdata() {
        final ProgressUtil progressUtil = new ProgressUtil();
        progressUtil.ShowProgress(this, true, true, "下载中...");
        HttpUtils httpUtils = new HttpUtils(10000);
        RequestParams params = new RequestParams();
        params.addBodyParameter("titleId", titleId);
        params.addBodyParameter("uId", uid);
        String pathurl = URLConstants.我的空间清单子项查询;
        httpUtils.send(HttpMethod.POST, pathurl, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    QDBean bean = gson.fromJson(responseInfo.result, QDBean.class);
                    if (bean.status == 0) {
                        listBeanList.clear();
                        listBeanList = bean.list;

                        setAdapter();
                    }
                } else {
                    Toast.makeText(QDZoneDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
                }
                progressUtil.dismiss();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                progressUtil.dismiss();
                Toast.makeText(QDZoneDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });

//        if (type != 1 && type != 5) {
//            HttpUtils httpUtils0 = new HttpUtils(10000);
//            RequestParams params0 = new RequestParams();
//            params0.addBodyParameter("titleId", titleId);
//            params0.addBodyParameter("type", "1");
//            params0.addBodyParameter("uId", uid);
//            httpUtils0.send(HttpMethod.POST, URLConstants.清单公告点赞, params0, new RequestCallBack<String>() {
//                @Override
//                public void onSuccess(ResponseInfo<String> responseInfo) {
//
//                }
//
//                @Override
//                public void onFailure(HttpException e, String s) {
//
//                }
//            });
//
//            HttpUtils httpUtils1 = new HttpUtils(10000);
//            RequestParams params1 = new RequestParams();
//            params1.addBodyParameter("titleId", titleId);
//            params1.addBodyParameter("uId", uid);
//            httpUtils1.send(HttpMethod.POST, URLConstants.清单公告下载数量, params1, new RequestCallBack<String>() {
//                @Override
//                public void onSuccess(ResponseInfo<String> responseInfo) {
//                    if (!TextUtils.isEmpty(responseInfo.result)) {
//                        Gson gson = new Gson();
//                        GONGGAODOWNBEAN bean = gson.fromJson(responseInfo.result, GONGGAODOWNBEAN.class);
//                        if (bean.status == 0) {
//                            lis.clear();
//                            lis = bean.list;
//                            if (lis.size() > 0) {
//                                goodnum = lis.get(0).goodNum + "";
//                                rednum = lis.get(0).redNum + "";
//                                notifyDataSetChanged();
//                            }
//                        }
//
//                    }
//                }
//
//                @Override
//                public void onFailure(HttpException e, String s) {
//
//                }
//            });
//
//        }
    }

    private void notifyDataSetChanged() {
        listAdapter.notifyDataSetChanged();
    }

//    List<GONGGAODOWNBEAN.ListBean> lis = new ArrayList<>();
//
//    class GONGGAODOWNBEAN {
//
//
//        /**
//         * status : 0
//         * downTime : 2017-06-16T10:55:55
//         * message : 成功
//         * list : [{"redNum":1,"noNum":0,"remark2":"","id":35,"remark1":"","goodNum":1,"titleId":"20170608144416483157","uid":5001,"changeTime":"2017-06-16T10:55:31"}]
//         * tDelList : null
//         * delList : null
//         */
//
//        public int status;
//        public String downTime;
//        public String message;
//        public Object tDelList;
//        public Object delList;
//        public List<ListBean> list;
//
//        public int getStatus() {
//            return status;
//        }
//
//        public void setStatus(int status) {
//            this.status = status;
//        }
//
//        public String getDownTime() {
//            return downTime;
//        }
//
//        public void setDownTime(String downTime) {
//            this.downTime = downTime;
//        }
//
//        public String getMessage() {
//            return message;
//        }
//
//        public void setMessage(String message) {
//            this.message = message;
//        }
//
//        public Object getTDelList() {
//            return tDelList;
//        }
//
//        public void setTDelList(Object tDelList) {
//            this.tDelList = tDelList;
//        }
//
//        public Object getDelList() {
//            return delList;
//        }
//
//        public void setDelList(Object delList) {
//            this.delList = delList;
//        }
//
//        public List<ListBean> getList() {
//            return list;
//        }
//
//        public void setList(List<ListBean> list) {
//            this.list = list;
//        }
//
//        public class ListBean {
//            /**
//             * redNum : 1
//             * noNum : 0
//             * remark2 :
//             * id : 35
//             * remark1 :
//             * goodNum : 1
//             * titleId : 20170608144416483157
//             * uid : 5001
//             * changeTime : 2017-06-16T10:55:31
//             */
//
//            public int redNum;
//            public int noNum;
//            public String remark2;
//            public int id;
//            public String remark1;
//            public int goodNum;
//            public String titleId;
//            public int uid;
//            public String changeTime;
//
//            public int getRedNum() {
//                return redNum;
//            }
//
//            public void setRedNum(int redNum) {
//                this.redNum = redNum;
//            }
//
//            public int getNoNum() {
//                return noNum;
//            }
//
//            public void setNoNum(int noNum) {
//                this.noNum = noNum;
//            }
//
//            public String getRemark2() {
//                return remark2;
//            }
//
//            public void setRemark2(String remark2) {
//                this.remark2 = remark2;
//            }
//
//            public int getId() {
//                return id;
//            }
//
//            public void setId(int id) {
//                this.id = id;
//            }
//
//            public String getRemark1() {
//                return remark1;
//            }
//
//            public void setRemark1(String remark1) {
//                this.remark1 = remark1;
//            }
//
//            public int getGoodNum() {
//                return goodNum;
//            }
//
//            public void setGoodNum(int goodNum) {
//                this.goodNum = goodNum;
//            }
//
//            public String getTitleId() {
//                return titleId;
//            }
//
//            public void setTitleId(String titleId) {
//                this.titleId = titleId;
//            }
//
//            public int getUid() {
//                return uid;
//            }
//
//            public void setUid(int uid) {
//                this.uid = uid;
//            }
//
//            public String getChangeTime() {
//                return changeTime;
//            }
//
//            public void setChangeTime(String changeTime) {
//                this.changeTime = changeTime;
//            }
//        }
//    }

    boolean isZan = false;


    @Override
    public void onBackPressed() {
        super.onBackPressed();
        this.finish();
    }

    private void isHongdian() {
        int isread = App.getDBcApplication().getOneNoteLYDataIsRead(titleId);
        if (isread > 0) {
            App.getDBcApplication().updateNoteTitleOther1(titleId, userid, 1);
        } else {
            App.getDBcApplication().updateNoteTitleOther1(titleId, userid, 0);
        }
    }

    boolean istitle1 = false;
    String where = "";

    class ListAdapter extends BaseAdapter {

        List<QDBean.ListBean> list;

        public ListAdapter(List<QDBean.ListBean> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size() + 2;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public int getItemViewType(int position) {
            if (position == 0) {
                return 0;
            } else if (position == list.size() + 1) {
                return 1;
            } else {
                return 2;
            }
        }

        @Override
        public int getViewTypeCount() {
            return 3;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            OneHolder oneHolder = null;
            TwoHolder twoHolder = null;
            int viewtype = getItemViewType(position);
            if (convertView == null) {
                switch (viewtype) {
                    case 0:
                        oneHolder = new OneHolder();
                        convertView = LayoutInflater.from(QDZoneDetailActivity.this).inflate(R.layout.dx_detail_header_view, parent, false);
                        oneHolder.title = (TextView) convertView.findViewById(R.id.title);
                        oneHolder.username = (TextView) convertView.findViewById(R.id.username);
                        oneHolder.header_image = (ImageView) convertView.findViewById(R.id.header_image);
                        convertView.setTag(oneHolder);
                        break;
                    case 1:
                        twoHolder = new TwoHolder();
                        convertView = LayoutInflater.from(QDZoneDetailActivity.this).inflate(R.layout.dx_detail_foolter_view, parent, false);
                        twoHolder.checkAlltext = (TextView) convertView.findViewById(R.id.checkAlltext);
                        twoHolder.lttext = (TextView) convertView.findViewById(R.id.lttext);
                        twoHolder.number = (TextView) convertView.findViewById(R.id.number);
                        twoHolder.zan = (TextView) convertView.findViewById(R.id.zan);
                        twoHolder.zan_num = (TextView) convertView.findViewById(R.id.zan_num);
                        twoHolder.newly_ll = (LinearLayout) convertView.findViewById(R.id.newly_ll);
                        twoHolder.guoqi_img = (ImageView) convertView.findViewById(R.id.guoqi_img);
                        twoHolder.bo = convertView.findViewById(R.id.bo);
                        twoHolder.create_time = convertView.findViewById(R.id.create_time);
                        twoHolder.ide = convertView.findViewById(R.id.ide);
                        convertView.setTag(twoHolder);
                        break;
                    case 2:
                        holder = new ViewHolder();

                        convertView = LayoutInflater.from(QDZoneDetailActivity.this).inflate(R.layout.qdfx_de_list_item, parent, false);
                        holder.content_tv = (TextView) convertView.findViewById(R.id.content_tv);
                        holder.xh = (TextView) convertView.findViewById(R.id.xh);
                        holder.dd = (ImageView) convertView.findViewById(R.id.dd);
                        holder.ch = (ImageView) convertView.findViewById(R.id.ch);
                        holder.guoqi_img = (ImageView) convertView.findViewById(R.id.guoqi_img);
                        holder.ll = (RelativeLayout) convertView.findViewById(R.id.ll);
                        holder.santai = (ImageView) convertView.findViewById(R.id.santai);
                        holder.emty_v = convertView.findViewById(R.id.emty_v);
                        holder.line = convertView.findViewById(R.id.line);
                        holder.cl = (LinearLayout) convertView.findViewById(R.id.cl);
                        holder.ly_tv = (TextView) convertView.findViewById(R.id.ly_tv);

                        convertView.setTag(holder);
                        break;
                }
            } else {
                switch (viewtype) {
                    case 0:
                        oneHolder = (OneHolder) convertView.getTag();
                        break;
                    case 1:
                        twoHolder = (TwoHolder) convertView.getTag();
                        break;
                    case 2:
                        holder = (ViewHolder) convertView.getTag();
                        break;
                }
            }
            switch (viewtype) {
                case 0:
                    if (title.isEmpty()) {
                        oneHolder.title.setVisibility(View.GONE);
                    } else {
                        oneHolder.title.setText(title);
                    }

//                    oneHolder.username.setText("@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));

                    if (path.isEmpty()) {
                        oneHolder.header_image.setVisibility(View.GONE);
                    } else {
                        oneHolder.header_image.setVisibility(View.VISIBLE);
                        String imageUrl = URLConstants.图片 + path + "&imageType=15&imageSizeType=1";
                        ImageLoader.getInstance().displayImage(imageUrl, oneHolder.header_image, base_options);
                    }

                    oneHolder.username.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                Intent intent = new Intent(context, NoteOtherListActivity.class);
                                intent.putExtra("name", name);
                                intent.putExtra("puid", uid);
                                startActivity(intent);
                            }
                        }
                    });
                    break;
                case 1:
                    twoHolder.number.setVisibility(View.GONE);
                    twoHolder.zan_num.setVisibility(View.GONE);
                    twoHolder.zan.setVisibility(View.GONE);
//                    if (type == 5) {
                        twoHolder.newly_ll.setVisibility(View.GONE);
//                    } else {
//                        twoHolder.newly_ll.setVisibility(View.VISIBLE);
//                    }
//                    twoHolder.number.setText("浏览" + StringUtils.getIsStringEqulesNull(rednum) + "次");
//                    twoHolder.zan_num.setText(StringUtils.getIsStringEqulesNull(goodnum) + "人");
//                    twoHolder.zan.setOnClickListener(new OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            if (!isGood) {
//                                good();
//                            }
//                        }
//                    });
//                    if (type != 1 && type != 5) {
//                        String rizhi = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.CHANGJIANDIANZAN, "");
//                        String[] ri = rizhi.split(",");
//                        if (ri.length > 0) {
//                            for (String item : ri) {
//                                if (item.equals(titleId)) {
//                                    twoHolder.zan.setTextColor(getResources().getColor(R.color.gongkai_txt));
//                                    twoHolder.zan.setBackground(getResources().getDrawable(R.drawable.zan_y_gray));
//                                    isGood = true;
//                                    break;
//                                }
//                            }
//                        }
//                    }
//
//                    if (isGood) {
//                        twoHolder.zan.setTextColor(getResources().getColor(R.color.gongkai_txt));
//                        twoHolder.zan.setBackground(getResources().getDrawable(R.drawable.zan_y_gray));
//                    }

                    twoHolder.bo.setVisibility(View.VISIBLE);
                    twoHolder.create_time.setText("创建时间:"+time.replace("T"," "));
                    twoHolder.ide.setText("云清单:#"+id);
                    break;
                case 2:
                    final ViewHolder finalHolder = holder;
                    if (list.size() > 0) {

                        NoteLYBean.PageBean.ItemsBean itemsBean = App.getDBcApplication().getOneNoteLYData(titleId, list.get(position - 1).id);
                        if (itemsBean != null) {
                            if (itemsBean.mess != null && itemsBean.lyName != null && itemsBean.cId == list.get(position - 1).id) {
                                holder.ly_tv.setVisibility(View.VISIBLE);
                                holder.ly_tv.setText("@" + itemsBean.lyName + ": " + itemsBean.mess);
                            } else {
                                holder.ly_tv.setVisibility(View.GONE);
                            }
                            if (type != 5) {
                                if (App.getDBcApplication().getOneNoteLYDataIsRead(titleId, list.get(position - 1).id) == 1) {
                                    holder.guoqi_img.setVisibility(View.VISIBLE);
                                } else {
                                    holder.guoqi_img.setVisibility(View.GONE);
                                }
                            }
                        }

                        if (!istitle1) {
                            if (!list.get(position - 1).contents.isEmpty()) {
                                title1 = list.get(position - 1).contents;
                                sendh(0);
                                istitle1 = true;
                            }
                        }

                        if (stylee == 0) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.VISIBLE);
                            if (type != 1) {
                                if (list.get(position - 1).endstate == 0) {
                                    holder.ch.setBackground(getResources().getDrawable(R.mipmap.btn_qd_unfinish_c));
                                } else {
                                    holder.ch.setBackground(getResources().getDrawable(R.mipmap.btn_qd_finish_c));
                                }
                            }
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 1) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.VISIBLE);
                            holder.xh.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 2) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.VISIBLE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 3) {
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.ll.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                            holder.emty_v.setVisibility(View.VISIBLE);
                        } else if (stylee == 4) {
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.santai.setVisibility(View.VISIBLE);
                            if (type != 1) {
                                if (list.get(position - 1).endstate == 0) {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai1));
                                } else if (list.get(position - 1).endstate == 1) {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai2));
                                } else {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai3));
                                }
                            }
                        }

                        setcolor(list.get(position - 1).contents, holder.content_tv);
                        holder.xh.setText((position) + ".");
                    }

                    break;
            }
            return convertView;
        }


        class ViewHolder {
            TextView xh, content_tv, ly_tv;
            ImageView ch, dd, santai, guoqi_img;
            View emty_v, line;
            RelativeLayout ll;
            LinearLayout cl;
        }

        class OneHolder {
            TextView title, username, number;
            ImageView header_image;
        }

        class TwoHolder {
            TextView checkAlltext, lttext, number, zan, zan_num,create_time,ide;
            LinearLayout newly_ll,bo;
            ImageView guoqi_img;
        }


    }

    //设置双#号包裹的文字颜色
    private void setcolor(String content, TextView editText) {
        if (content.length() > 1) {
            SpannableStringBuilder builder = new SpannableStringBuilder(content);
            List<Integer> integerList = new ArrayList<>();
            int index = 0;
            int count = hit(content, "#");
            if (count > 1) {
                if (count % 2 == 0) {
                    for (int i = 0; i < count; i++) {
                        if (i == 0) {
                            index = content.indexOf("#");
                        } else {
                            index = content.indexOf("#", index + 1);
                        }
                        integerList.add(index);
                    }
                    for (int i = 0; i < integerList.size(); i++) {
                        if (i > 0) {
                            if (i % 2 != 0) {
                                ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor("#df7926"));
                                builder.setSpan(span, integerList.get(i - 1), integerList.get(i) + 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                        }
                    }
                    editText.setText(builder);
                } else {
                    for (int i = 0; i < count - 1; i++) {
                        if (i == 0) {
                            index = content.indexOf("#");
                        } else {
                            index = content.indexOf("#", index + 1);
                        }
                        integerList.add(index);

                    }
                    for (int i = 0; i < integerList.size(); i++) {
                        if (i > 0) {
                            if (i % 2 != 0) {
                                ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor("#df7926"));
                                builder.setSpan(span, integerList.get(i - 1), integerList.get(i) + 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                        }
                    }
                    editText.setText(builder);
                }
            } else {
                editText.setText(content);
            }
        } else {
            editText.setText(content);
        }
        editText.setLineSpacing(20, 1.5f);
    }

    /**
     * @param a 被匹配的长字符串
     * @param b 匹配的短字符串
     * @return 匹配次数
     */
    public int hit(String a, String b) {
        if (a.length() < b.length()) {
            return 0;
        }
        char[] a_t = a.toCharArray();
        int count = 0;

        for (int i = 0; i < a.length(); i++) {
            StringBuffer buffer = new StringBuffer();
            for (int j = 0; j < b.length(); j++) {
                buffer.append(a_t[i + j]);
            }
            if (buffer.toString().equals(b)) {
                count++;
            }
        }

        return count;
    }


    public class QDBean {

        /**
         * delList : null
         * downTime : 2018-06-26T13:50:11
         * list : [{"changetime":"2018-06-26T13:49:55","contents":"判断是否有图片","cpath":"","createTime":"2018-06-26T13:49:55","curl":"","endstate":0,"id":425,"imgPath":null,"imgUrl":null,"lType":null,"nums":"0","orderId":0,"remark":null,"remark1":null,"remark2":null,"remark3":"0","remark4":"0","remark5":null,"remark6":null,"remark7":null,"remark8":null,"shareUrl":null,"style":null,"titleId":"20180521142155573195","titles":null,"uid":1318776},{"changetime":"2018-06-26T13:49:55","contents":"判断是否有标题","cpath":"","createTime":"2018-06-26T13:49:55","curl":"","endstate":0,"id":426,"imgPath":null,"imgUrl":null,"lType":null,"nums":"0","orderId":1,"remark":null,"remark1":null,"remark2":null,"remark3":"0","remark4":"0","remark5":null,"remark6":null,"remark7":null,"remark8":null,"shareUrl":null,"style":null,"titleId":"20180521142155573195","titles":null,"uid":1318776},{"changetime":"2018-06-26T13:49:55","contents":"判断是否有子项，子项处理","cpath":"","createTime":"2018-06-26T13:49:55","curl":"","endstate":0,"id":427,"imgPath":null,"imgUrl":null,"lType":null,"nums":"0","orderId":2,"remark":null,"remark1":null,"remark2":null,"remark3":"0","remark4":"0","remark5":null,"remark6":null,"remark7":null,"remark8":null,"shareUrl":null,"style":null,"titleId":"20180521142155573195","titles":null,"uid":1318776},{"changetime":"2018-06-26T13:49:55","contents":"数据库插入","cpath":"","createTime":"2018-06-26T13:49:55","curl":"","endstate":0,"id":428,"imgPath":null,"imgUrl":null,"lType":null,"nums":"0","orderId":3,"remark":null,"remark1":null,"remark2":null,"remark3":"0","remark4":"0","remark5":null,"remark6":null,"remark7":null,"remark8":null,"shareUrl":null,"style":null,"titleId":"20180521142155573195","titles":null,"uid":1318776},{"changetime":"2018-06-26T13:49:55","contents":"闹钟写入","cpath":"","createTime":"2018-06-26T13:49:55","curl":"","endstate":0,"id":429,"imgPath":null,"imgUrl":null,"lType":null,"nums":"0","orderId":4,"remark":null,"remark1":null,"remark2":null,"remark3":"0","remark4":"0","remark5":null,"remark6":null,"remark7":null,"remark8":null,"shareUrl":null,"style":null,"titleId":"20180521142155573195","titles":null,"uid":1318776},{"changetime":"2018-06-26T13:49:55","contents":"日程刷新","cpath":"","createTime":"2018-06-26T13:49:55","curl":"","endstate":0,"id":430,"imgPath":null,"imgUrl":null,"lType":null,"nums":"0","orderId":5,"remark":null,"remark1":null,"remark2":null,"remark3":"0","remark4":"0","remark5":null,"remark6":null,"remark7":null,"remark8":null,"shareUrl":null,"style":null,"titleId":"20180521142155573195","titles":null,"uid":1318776}]
         * message : 成功
         * page : null
         * status : 0
         * tDelList : null
         */

        public Object delList;
        public String downTime;
        public String message;
        public Object page;
        public int status;
        public Object tDelList;
        public List<ListBean> list;

        public Object getDelList() {
            return delList;
        }

        public void setDelList(Object delList) {
            this.delList = delList;
        }

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public Object getPage() {
            return page;
        }

        public void setPage(Object page) {
            this.page = page;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public Object getTDelList() {
            return tDelList;
        }

        public void setTDelList(Object tDelList) {
            this.tDelList = tDelList;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public class ListBean {
            /**
             * changetime : 2018-06-26T13:49:55
             * contents : 判断是否有图片
             * cpath :
             * createTime : 2018-06-26T13:49:55
             * curl :
             * endstate : 0
             * id : 425
             * imgPath : null
             * imgUrl : null
             * lType : null
             * nums : 0
             * orderId : 0
             * remark : null
             * remark1 : null
             * remark2 : null
             * remark3 : 0
             * remark4 : 0
             * remark5 : null
             * remark6 : null
             * remark7 : null
             * remark8 : null
             * shareUrl : null
             * style : null
             * titleId : 20180521142155573195
             * titles : null
             * uid : 1318776
             */

            public String changetime;
            public String contents;
            public String cpath;
            public String createTime;
            public String curl;
            public int endstate;
            public int id;
            public String imgPath;
            public String imgUrl;
            public String lType;
            public String nums;
            public int orderId;
            public String remark;
            public String remark1;
            public String remark2;
            public String remark3;
            public String remark4;
            public String remark5;
            public String remark6;
            public String remark7;
            public String remark8;
            public String shareUrl;
            public String style;
            public String titleId;
            public String titles;
            public int uid;

            public String getChangetime() {
                return changetime;
            }

            public void setChangetime(String changetime) {
                this.changetime = changetime;
            }

            public String getContents() {
                return contents;
            }

            public void setContents(String contents) {
                this.contents = contents;
            }

            public String getCpath() {
                return cpath;
            }

            public void setCpath(String cpath) {
                this.cpath = cpath;
            }

            public String getCreateTime() {
                return createTime;
            }

            public void setCreateTime(String createTime) {
                this.createTime = createTime;
            }

            public String getCurl() {
                return curl;
            }

            public void setCurl(String curl) {
                this.curl = curl;
            }

            public int getEndstate() {
                return endstate;
            }

            public void setEndstate(int endstate) {
                this.endstate = endstate;
            }

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public Object getImgPath() {
                return imgPath;
            }

            public void setImgPath(String imgPath) {
                this.imgPath = imgPath;
            }

            public String getImgUrl() {
                return imgUrl;
            }

            public void setImgUrl(String imgUrl) {
                this.imgUrl = imgUrl;
            }

            public String getLType() {
                return lType;
            }

            public void setLType(String lType) {
                this.lType = lType;
            }

            public String getNums() {
                return nums;
            }

            public void setNums(String nums) {
                this.nums = nums;
            }

            public int getOrderId() {
                return orderId;
            }

            public void setOrderId(int orderId) {
                this.orderId = orderId;
            }

            public String getRemark() {
                return remark;
            }

            public void setRemark(String remark) {
                this.remark = remark;
            }

            public String getRemark1() {
                return remark1;
            }

            public void setRemark1(String remark1) {
                this.remark1 = remark1;
            }

            public String getRemark2() {
                return remark2;
            }

            public void setRemark2(String remark2) {
                this.remark2 = remark2;
            }

            public String getRemark3() {
                return remark3;
            }

            public void setRemark3(String remark3) {
                this.remark3 = remark3;
            }

            public String getRemark4() {
                return remark4;
            }

            public void setRemark4(String remark4) {
                this.remark4 = remark4;
            }

            public String getRemark5() {
                return remark5;
            }

            public void setRemark5(String remark5) {
                this.remark5 = remark5;
            }

            public String getRemark6() {
                return remark6;
            }

            public void setRemark6(String remark6) {
                this.remark6 = remark6;
            }

            public String getRemark7() {
                return remark7;
            }

            public void setRemark7(String remark7) {
                this.remark7 = remark7;
            }

            public String getRemark8() {
                return remark8;
            }

            public void setRemark8(String remark8) {
                this.remark8 = remark8;
            }

            public String getShareUrl() {
                return shareUrl;
            }

            public void setShareUrl(String shareUrl) {
                this.shareUrl = shareUrl;
            }

            public String getStyle() {
                return style;
            }

            public void setStyle(String style) {
                this.style = style;
            }

            public String getTitleId() {
                return titleId;
            }

            public void setTitleId(String titleId) {
                this.titleId = titleId;
            }

            public String getTitles() {
                return titles;
            }

            public void setTitles(String titles) {
                this.titles = titles;
            }

            public int getUid() {
                return uid;
            }

            public void setUid(int uid) {
                this.uid = uid;
            }
        }
    }

}
